package com.rx.base.demo.common.exception;

import com.rx.base.demo.common.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(RuntimeException.class)
    public BaseResult<String> handle(RuntimeException e) {
        logger.error("发生 RuntimeException 异常{}", e.getMessage());
        return BaseResult.error(e);
    }
    @ExceptionHandler(BusinessException.class)
    public BaseResult<String> handle(BusinessException e) {
        logger.error("发生 BusinessException 异常{}", e.getMessage());
        return BaseResult.error(e.getResponseCode().getCode(), e.getResponseCode().getMsg() + "" + e.getMessage());
    }
}
